package com.bat.conf;

import feign.Request;
import org.springframework.stereotype.Service;

import java.net.HttpURLConnection;

/**
 *  feign超时　通过threadlocal传递过来
 * @Description:
 * @Author: zpf
 * @Date: 2020/7/17 下午6:28
 */
@Service
public class MyRequestOptions extends Request.Options {
    private final int connectTimeoutMillis;
    private final int readTimeoutMillis;
    private final boolean followRedirects;

    public MyRequestOptions(final int connectTimeoutMillis, final int readTimeoutMillis,
        final boolean followRedirects) {
        this.connectTimeoutMillis = connectTimeoutMillis;
        this.readTimeoutMillis = readTimeoutMillis;
        this.followRedirects = followRedirects;
    }

    public MyRequestOptions(final int connectTimeoutMillis, final int readTimeoutMillis) {
        this(connectTimeoutMillis, readTimeoutMillis, true);
    }

    public MyRequestOptions() {
        this(10 * 1000, 60 * 1000);
    }

    /**
     * Defaults to 10 seconds. {@code 0} implies no timeout.
     *
     * @see HttpURLConnection#getConnectTimeout()
     */
    @Override
    public int connectTimeoutMillis() {
        return connectTimeoutMillis;
    }

    /**
     * Defaults to 60 seconds. {@code 0} implies no timeout.
     *
     * @see HttpURLConnection#getReadTimeout()
     */
    @Override
    public int readTimeoutMillis() {
        return readTimeoutMillis;
    }

    /**
     * Defaults to true. {@code false} tells the client to not follow the redirections.
     *
     * @see HttpURLConnection#getFollowRedirects()
     */
    @Override
    public boolean isFollowRedirects() {
        return followRedirects;
    }
}
